class RouterX {



/**
 * 使用说明
 * this.$routerX.push(string,jsObj)			//路由切换		arg1:路径	arg2:参数
 * this.$routerX.replace(string,jsObj)		//路由重定向		arg1:路径	arg2:参数
 * this.$routerX.switchTab(string,jsObj)	//切换tab		arg1:路径	arg2:参数
 */
	constructor() {};
	//路由切换方法
	static push(path, params = {}) {
		let paramsStr = '?';
		if (JSON.stringify(params) != '{}') {
			for (let key in params) {
				paramsStr += `${key}=${params[key]}&`;
			}
			paramsStr = paramsStr.substring(0, paramsStr.lastIndexOf('&'));
			let url = path + paramsStr;
			uni.navigateTo({
				url: url
			})
		} else {
			uni.navigateTo({
				url: path
			})
		}
	}
	//路由从定向
	static replace(path, params = {}) {
		let paramsStr = '?';
		if (JSON.stringify(params) != '{}') {
			for (let key in params) {
				paramsStr += `${key}=${params[key]}&`;
			}
			paramsStr = paramsStr.substring(0, paramsStr.lastIndexOf('&'));
			let url = path + paramsStr;
			uni.redirectTo()({
				url: url
			})
		} else {
			uni.redirectTo({
				url: path
			})
		}
	}

	//tab切换
	static switchTab(path, params = {}) {
		let paramsStr = '?';
		if (JSON.stringify(params) != '{}') {
			for (let key in params) {
				paramsStr += `${key}=${params[key]}&`;
			}
			paramsStr = paramsStr.substring(0, paramsStr.lastIndexOf('&'));
			let url = path + paramsStr;
			uni.switchTab({
				url: url
			})
		} else {
			uni.switchTab({
				url: path
			})
		}
	}
}

export default RouterX;
